import asyncio
import aiohttp


async def download(url):
    print('%s下载中' % url)
    await asyncio.sleep(1)

    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            content = await response.read()
            return content, response.status


async def write_file(filename, content):
    with open(filename, 'wb') as f:
        f.write(content)
    print(filename, 'Write OK')


async def save(url, filename):
    content, code = await download(url)
    await write_file(filename, content)
    print(url, filename, '保存成功!')


if __name__ == '__main__':
    # 直接使用 asyncio.gather()，不需要 asyncio.run()
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.gather(
        save('https://www.baidu.com', 'baidu.html'),
        save('https://www.jd.com', 'jd.html'),
        save('https://mail.qq.com', 'qq_mail.html')
    ))